package leetcode.Greedy;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class Lc763 {

    public List<Integer> partitionLabels(String s) {
        HashMap<Character, Integer> map = new HashMap<>();

        for (int i = 0; i < s.length(); i++) {
            map.put(s.charAt(i), i);
        }
        ArrayList<Integer> list = new ArrayList<>();
        for (int i = 0; i < s.length();) {
            char c = s.charAt(i);
            int idx = map.get(c);
            int start = i;
            while (i <= idx) {
                idx = Math.max(idx, map.get(s.charAt(i)));
                i++;
            }
            list.add(idx - start + 1);
        }
        return list;
    }



    public static void main(String[] args) {
        Lc763 lc763 = new Lc763();
        System.out.println(lc763.partitionLabels("ababcbacadefegdehijhklij"));
    }

}








